﻿var columns =
            [
                 { display: 'Key', name: 'key', type: 'text', hide: 1 },
                { display: '角色编码', name: 'Code', width: 120 },
                { display: '角色名称', name: 'Name', width: 140 },
                { display: '角色描述', name: 'Name', width: 200 }
             ];

//init controls
var manager;
$(document).ready(function () {
    initligerGrid();
});
function initligerGrid() {
    manager = null;
    manager = $("#operationGrid").ligerGrid({
        columns: columns,
        title: '菜单类别',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        rownumbers: true,
        checkbox: false,
        toolbar: { items: [
                            { text: '增加', click: addRole, icon: 'add' },
                            { line: true },
                            { text: '修改', click: modifyRole, icon: 'modify' },
                            { line: true },
                            { text: '删除', click: deleteRole, img: '../Content/images/delete.gif' },
                            { line: true },
                            { text: '角色授权', click: authorizate, img: '../Content/images/table_relationship.png' }
                           ]
        },
        url: "../Role/GetJsonOfRoles"
    });
}
//add
function addRole() {

    $.ligerDialog.open({ url: '../Role/Add',height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });

    //    var returnValue = window.showModalDialog('../Operation/Add', window, "help:No;resizable:No;status:No;scroll:yes;dialogWidth=500px;dialogHeight=400px");
}
//delete
function deleteRole() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
        if (yes) {
            $.get("../Role/Delete?roleId=" + row["Key"].toString(), {}, function (data) {
                if (data != undefined && data == "ok") {
                    initligerGrid();
                }
            });
        }
    });
}
//update 
function modifyRole() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    $.ligerDialog.open({ url: '../Role/Edit?roleId=' + row["Key"].toString(),height: getDialogHeight(), width: getDialogWidth(),isResize: true, isHidden: false
    });
}
//给角色赋权限
function authorizate() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要赋权的行!'); return;
    }
    $.ligerDialog.open({ url: '../Permission/PermissionTreeDate?roleId=' + row["Key"].toString(), 
    height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
}